package com.foreverwin.mes.production.controller;


import com.foreverwin.mes.core.base.AjaxResult;
import com.foreverwin.mes.core.base.FrontPage;
import com.foreverwin.mes.core.utils.StringUtils;
import com.foreverwin.mes.production.model.WorkDayRestTimeDetail;
import com.foreverwin.mes.production.service.WorkDayRestTimeDetailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Syngna
 * @since 2018-11-27
 */
@RestController
@RequestMapping("/workDayRestTimeDetails")
public class WorkDayRestTimeDetailController {
    private final Logger logger = LoggerFactory.getLogger(WorkDayRestTimeDetailController.class);

    @Autowired
    public WorkDayRestTimeDetailService workDayRestTimeDetailService;

    /**
     * 根据id查询
     *
     * @param id 主键
     * @return
     */
    @GetMapping("/{id:.+}")
    public AjaxResult getWorkDayRestTimeDetailById(@PathVariable String id) {
        WorkDayRestTimeDetail result = null;
        try {
            result = workDayRestTimeDetailService.selectById(id);
        } catch (Exception e) {
            logger.error("getWorkDayRestTimeDetailById -=- {}", e.toString());
            return AjaxResult.error(StringUtils.isBlank(e.getMessage()) ? e.toString() : e.getMessage());
        }
        return AjaxResult.success(result);
    }

    /**
     * 查询所有数据
     *
     * @return
     */
    @GetMapping("")
    public AjaxResult getWorkDayRestTimeDetailList() {
        List result = new ArrayList();
        try {
            result = workDayRestTimeDetailService.selectList();
        } catch (Exception e) {
            logger.error("getWorkDayRestTimeDetailList -=- {}", e.toString());
            return AjaxResult.error(StringUtils.isBlank(e.getMessage()) ? e.toString() : e.getMessage());
        }
        return AjaxResult.success(result);
    }

    /**
     * 分页查询数据
     *
     * @param frontPage 分页信息
     * @return
     */
    @GetMapping("/getWorkDayRestTimeDetailPageList")
    public AjaxResult getWorkDayRestTimeDetailPageList(FrontPage frontPage) {
        List result = new ArrayList();
        try {
            result = workDayRestTimeDetailService.selectPage(frontPage).getRecords();
        } catch (Exception e) {
            logger.error("getWorkDayRestTimeDetailPageList -=- {}", e.toString());
            return AjaxResult.error(StringUtils.isBlank(e.getMessage()) ? e.toString() : e.getMessage());
        }
        return AjaxResult.success(result);
    }

}